Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drastically speed up Monoid[Map[K, V]] instance. #1300

Merged
merged 4 commits into from
Aug 19, 2016

Conversation

non
Copy link
Contributor

@non non commented Aug 19, 2016

This commit fixes a number of problems I introduced with cats-kernel.

  1. Map's monoid was not overriding combineAll
  2. It was also doing the wrong thing for combine
  3. Monoid should have overridden combineAllOption

The performance for map's combine is 150x faster after this commit,
and combineAll is 780x faster. Rather than focusing on how good
these speed ups are, I want to apologize for how bad the
implementations were previously. The new combine is competitive with
other implementations, and combineAll is about x5 faster than the
equivalent code using combine.

(All figures using before/after numbers for the given benchmark.)

Thanks to Adelbert and Travis for noticing this problem. Also thanks
to Travis for producing this benchmark! Finally, thanks to Oscar for
helping me look at and fix this issue.

This commit fixes a number of problems I introduced with cats-kernel.

 1. Map's monoid was not overriding combineAll
 2. It was also doing the wrong thing for combine
 3. Monoid should have overridden combineAllOption

The performance for map's `combine` is 150x faster after this commit,
and `combineAll` is 780x faster. Rather than focusing on how good
these speed ups are, I want to apologize for how bad the
implementations were previously. The new `combine` is competitive with
other implementations, and `combineAll` is about x5 faster than the
equivalent code using combine.

(All figures using before/after numbers for the given benchmark.)

Thanks to Adelbert and Travis for noticing this problem. Also thanks
to Travis for producing this benchmark! Finally, thanks to Oscar for
helping me look at and fix this issue.
@non
Copy link
Contributor Author

non commented Aug 19, 2016

This fixes #1290.

@johnynek
Copy link
Contributor

👍

@travisbrown
Copy link
Contributor

👍, thanks!

result
}

def wrapMutableMap[K, V](m: mutable.Map[K, V]): Map[K, V] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you remove this, it becomes unusable from the outside. That was the reason for it, I think, to allow using it from say algebra.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right! I'll add them back so we can use them in Algebra (and beyond).

Since we made WrappedMutableMap private to the kernel, we
need something like this so that Algebra, Spire, Algebird, etc.
can all take advantage of this basic pattern.
@codecov-io
Copy link

codecov-io commented Aug 19, 2016

Current coverage is 90.76% (diff: 100%)

Merging #1300 into master will increase coverage by <.01%

@@             master      #1300   diff @@
==========================================
  Files           234        234          
  Lines          3377       3380     +3   
  Methods        3323       3323          
  Messages          0          0          
  Branches         52         55     +3   
==========================================
+ Hits           3065       3068     +3   
  Misses          312        312          
  Partials          0          0          

Sunburst

Powered by Codecov. Last update 1b65c5a...6043c7f

@non
Copy link
Contributor Author

non commented Aug 19, 2016

Two sign-offs, I'm merging.

@non non merged commit 6137fee into typelevel:master Aug 19, 2016
@non non removed the in progress label Aug 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants